<template>
    <div>
        <h1>添加</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>选择房型</td>
                    <td><select v-model="info.lid">
            <option value="">请选择</option>
            <option :value="value.hid" v-for="value in level" :key="value.hid">{{value.hname}}</option>  
        </select></td>
                </tr>
                 <tr>
                    <td>房号</td>
                    <td><input type="text" v-model="info.num"></td>
                </tr>
                  <tr>
                    <td>排序</td>
                    <td><input type="text" v-model="info.name"></td>
                </tr>
                 <tr>
                    <td>备注</td>
                    <td><input type="text" v-model="info.order"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="add"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import router from '@/router';

let info:any=ref({
  "id": 0,
  "num": "",
  "name": "",
  "order": "",
  "lid": ""
})

onMounted(()=>{
    GetLevel();
})
//下拉
let level:any=ref([])

const GetLevel=()=>{
    axios({
        url:'https://localhost:7058/api/House/HouseLevel',
        method:'get',
    })
    .then((res)=>{
        console.log(res);
        level.value=res.data
    })
    .catch((err)=>{
        console.log(err);
    })
}
const add=()=>{
    if(info.value.num==""){
        alert("房号不能为空");
        return;
    }
     if(info.value.name==""){
        alert("排序不能为空");
        return;
    }
     if(info.value.order==""){
        alert("备注不能为空");
        return;
    }
    axios({
        url:'https://localhost:7058/api/House/add',
        method:'post',
        data:info.value
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0){
            alert("添加成功")
        }
        
    })
    .catch((err)=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>